package com.cloudkinto.appletController.stock;


import com.cloudkinto.appletservice.stock.AppletStockTransferService;
import com.cloudkinto.base.BaseController;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.product.ProductInfoService;
import com.cloudkinto.service.stock.StockRecordService;
import com.cloudkinto.service.stock.StockTransferService;
import com.cloudkinto.service.stock.vo.record.StockRecordPageRes;
import com.cloudkinto.service.stock.vo.transfer.StockTransferAddReq;
import com.cloudkinto.service.stock.vo.transfer.StockTransferDetail;
import com.cloudkinto.service.stock.vo.transfer.StockTransferPageRes;
import com.cloudkinto.service.stock.vo.transfer.StockTransferVerifyReq;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 张永远
 * @since 2020-06-11
 */
@RestController
@Api(tags = "小程序库内调货模块")
@RequestMapping("/api/applet/stockTransfer")
public class AppletStockTransferController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(AppletStockTransferController.class);

    @Autowired
    private StockTransferService stockTransferService;


    @UserSessionRequired
    @GetMapping("/listPage")
    @ApiOperation(value = "查询（分页）", notes = "查询（分页）")
    @ApiImplicitParams({@ApiImplicitParam(name = "keyword", value = "关键字", paramType = "query"),
            @ApiImplicitParam(name = "current", value = "当前页", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "0 未审核 1已审核", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", paramType = "query")})
    @ApiResponses({@ApiResponse(code = 200, message = "", response = StockTransferPageRes.class)})
    public PageResult listPage(HttpServletRequest request) {
        Long companyId = getCompanyId();
        Long userId = getCurrentUserId();
        Map<String, String> map = new HashMap<>();
        String type = request.getParameter("type");
        String keyword = request.getParameter("keyword");
        String current = request.getParameter("current");
        String size = request.getParameter("pageSize");
        map.put("keyword", keyword);
        map.put("type", type);
        map.put("companyId", companyId + "");
        map.put("current", current);
        map.put("pageSize", size);
        return stockTransferService.getListPage(map, userId);
    }
    @UserSessionRequired
    @PostMapping("verify")
    @ApiOperation(value = "审核操作", notes = "确认操作")
    public SingleResult verify(@RequestBody @Validated StockTransferVerifyReq req) {
        Long userId = getCurrentUserId();
        stockTransferService.verify(req, userId);
        return SingleResult.success();
    }


}

